import '../model/daydata.dart';

import '../helper/dioHelper.dart';

class SumDay {
  int ID;
  double SumWr;
  double SumWz;
  double SumWf;
  double SumWq;
  double SumSWDL;
  double SumZFDL;
  double MaxSWDL;
  double MinSWDL;
  double AverFDFHL;
  double AverH1;
  double MaxH1;
  double MinH1;
  double MaxR;
  double MinR;
  double AverR;
  double MaxQ;
  double MinQ;
  double AverQ;
  double AverQf;
  double AverQp;
  double AverHSL;
  double SumTFQS;
  double SumP;
  List<DayData> DList;

  SumDay(
      this.ID,
      this.SumWr,
      this.SumWz,
      this.SumWf,
      this.SumWq,
      this.SumSWDL,
      this.SumZFDL,
      this.MaxSWDL,
      this.MinSWDL,
      this.AverFDFHL,
      this.AverH1,
      this.MaxH1,
      this.MinH1,
      this.MaxR,
      this.MinR,
      this.AverR,
      this.MaxQ,
      this.MinQ,
      this.AverQ,
      this.AverQf,
      this.AverQp,
      this.AverHSL,
      this.SumTFQS,
      this.SumP,
      this.DList);

  SumDay.fromJson(Map<String, dynamic> json)
      : ID = 0,
        SumWr = json["SumWr"] * 1.0,
        SumWz = json["SumWz"] * 1.0,
        SumWf = json["SumWf"] * 1.0,
        SumWq = json["SumWq"] * 1.0,
        SumSWDL = json["SumSWDL"] * 1.0,
        //SumZFDL = json["SumZFDL"] * 1.0,
        SumZFDL = 0,
        MaxSWDL = json["MaxSWDL"] * 1.0,
        MinSWDL = json["MinSWDL"] * 1.0,
        AverFDFHL = json["AverFDFHL"] * 1.0,
        AverH1 = json["AverH1"] * 1.0,
        MaxH1 = json["MaxH1"] * 1.0,
        MinH1 = json["MinH1"] * 1.0,
        MaxR = json["MaxR"] * 1.0,
        MinR = json["MinR"] * 1.0,
        AverR = json["AverR"] * 1.0,
        MaxQ = json["MaxQ"] * 1.0,
        MinQ = json["MinQ"] * 1.0,
        AverQ = json["AverQ"] * 1.0,
        AverQf = json["AverQf"] * 1.0,
        AverQp = json["AverQp"] * 1.0,
        AverHSL = json["AverHSL"] * 1.0,
        SumTFQS = json["SumTFQS"] * 1.0,
        SumP = json["SumP"] * 1.0,
        DList = DayData.GetListByValue(json["DList"]);

  Map<String, dynamic> toJson() => {
        'ID': ID,
        'SumWr': SumWr,
        'SumWz': SumWz,
        'SumWf': SumWf,
        'SumWq': SumWq,
        'SumSWDL': SumSWDL,
        'SumZFDL': SumZFDL,
        'MaxSWDL': MaxSWDL,
        'MinSWDL': MinSWDL,
        'AverFDFHL': AverFDFHL,
        'AverH1': AverH1,
        'MaxH1': MaxH1,
        'MinH1': MinH1,
        'MaxR': MaxR,
        'MinR': MinR,
        'AverR': AverR,
        'MaxQ': MaxQ,
        'MinQ': MinQ,
        'AverQ': AverQ,
        'AverQf': AverQf,
        'AverQp': AverQp,
        'AverHSL': AverHSL,
        'SumTFQS': SumTFQS,
        'SumP': SumP,
        'DList': DList,
      };
  static Future<bool> Add(SumDay x1) async {
    var response = await DioHelper.Post("/SumDay/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(SumDay x1) async {
    var response = await DioHelper.Post("/SumDay/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(SumDay x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/SumDay/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<SumDay?> Get(String t1, String t2) async {
    // print(DioHelper.BaseUrl + "/DayData/GetSum?t1=$t1&t2=$t2");
    var response = await DioHelper.Get("/DayData/GetSum?t1=$t1&t2=$t2", {});
    print(response.data);
    if (response.statusCode == 200) return new SumDay.fromJson(response.data);
    return null;
  }

  static Future<List<SumDay>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/SumDay/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <SumDay>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new SumDay.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<SumDay>> GetAllList() async {
    var response = await DioHelper.Get("/SumDay/GetAllList", {});
    var list1 = <SumDay>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new SumDay.fromJson(x));
      }
    }
    return list1;
  }
}
